Skip to content

Первая версия решений#24

Open
Ivan-Voronyuk wants to merge 2 commits intoDafeCpp:mainfrom
Ivan-Voronyuk:main
Open

Первая версия решений#24
Ivan-Voronyuk wants to merge 2 commits intoDafeCpp:mainfrom
Ivan-Voronyuk:main

Conversation

@Ivan-Voronyuk
Copy link
Copy Markdown

8 задач
К сожалению, в некоторых местах могут быть неаккуратные названия функций/переменных.

Solution to 8 tasks.
Some code lacks formatting. Will probably be fixed in future versions.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 15 out of 28. Check the log or trigger a new build to see more.

Comment thread task_01/src/main.cpp
#include "solution.hpp"

int main() {
std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl;
std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << '\n';

Comment thread task_01/src/main.cpp
int main() {
std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl;
std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 5, 0, 4) == 4)
<< std::endl; // Stack []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
<< std::endl; // Stack []
<< '\n'; // Stack []

Comment thread task_02/src/test.cpp

for (unsigned int repeation = 0; repeation < 1000; ++repeation) {
constexpr unsigned int N = 1000;
std::array<int, N> min;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: uninitialized record type: 'min' [cppcoreguidelines-pro-type-member-init]

Suggested change
std::array<int, N> min;
std::array<int, N> min{};

Comment thread task_02/src/test.cpp
ASSERT_EQ(min[0], mstack.GetMin()); // forward pass - zero
for (unsigned int i = 1; i < N; ++i) {
int value = dist(rng);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

      min[i] = std::min(min[i - 1], value);
                        ^

Comment thread task_02/src/test.cpp
ASSERT_EQ(min[0], mstack.GetMin()); // forward pass - zero
for (unsigned int i = 1; i < N; ++i) {
int value = dist(rng);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

      min[i] = std::min(min[i - 1], value);
      ^

Comment thread task_05/src/sorting.cpp
return heapsort_inplace(arr);
}

inline void heapify(std::vector<int>& arr, uint I, uint L) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'heapify' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
inline void heapify(std::vector<int>& arr, uint I, uint L) {
inline static void heapify(std::vector<int>& arr, uint I, uint L) {

Comment thread task_05/src/sorting.cpp

inline void heapify(std::vector<int>& arr, uint I, uint L) {
uint next = I;
do {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: avoid do-while loops [cppcoreguidelines-avoid-do-while]

  do {
  ^

Comment thread task_05/src/test.cpp

sortings::qsort_inplace(arr);

int target_res = (1 << std::popcount(i)) - 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'popcount' in namespace 'std'; did you mean '__popcount'? [clang-diagnostic-error]

Suggested change
int target_res = (1 << std::popcount(i)) - 1;
int target_res = (1 << std::__popcount(i)) - 1;
Additional context

/usr/include/c++/13/bit:288: '__popcount' declared here

    __popcount(_Tp __x) noexcept
    ^

Comment thread task_05/src/test.cpp

for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j];

ASSERT_EQ(std::format("{:016b}", target_res),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

    ASSERT_EQ(std::format("{:016b}", target_res),
                   ^
Additional context

/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'

#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                              ^

/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'

  ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
                                                              ^

/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'

  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
                                   ^

/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'

  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
                                      ^

/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'

  if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                   ^

Comment thread task_05/src/test.cpp
for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j];

ASSERT_EQ(std::format("{:016b}", target_res),
std::format("{:016b}", actual_res))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

              std::format("{:016b}", actual_res))
                   ^
Additional context

/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'

#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                                    ^

/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'

  ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
                                                                    ^

/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'

  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
                                       ^

/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'

  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
                                          ^

/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'

  if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                   ^

Fixed first task random test fail
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_05/src/test.cpp

ASSERT_EQ(std::format("{:016b}", target_res),
std::format("{:016b}", actual_res))
<< std::format("sorting failed on binary pattern {} {:016b}", i, i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

        << std::format("sorting failed on binary pattern {} {:016b}", i, i);
                ^

Comment thread task_05/src/test.cpp

sortings::heapsort_inplace(arr);

int target_res = (1 << std::popcount(i)) - 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'popcount' in namespace 'std'; did you mean '__popcount'? [clang-diagnostic-error]

Suggested change
int target_res = (1 << std::popcount(i)) - 1;
int target_res = (1 << std::__popcount(i)) - 1;
Additional context

/usr/include/c++/13/bit:288: '__popcount' declared here

    __popcount(_Tp __x) noexcept
    ^

Comment thread task_05/src/test.cpp

for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j];

ASSERT_EQ(std::format("{:016b}", target_res),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

    ASSERT_EQ(std::format("{:016b}", target_res),
                   ^
Additional context

/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'

#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                              ^

/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'

  ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
                                                              ^

/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'

  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
                                   ^

/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'

  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
                                      ^

/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'

  if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                   ^

Comment thread task_05/src/test.cpp
for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j];

ASSERT_EQ(std::format("{:016b}", target_res),
std::format("{:016b}", actual_res))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

              std::format("{:016b}", actual_res))
                   ^
Additional context

/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'

#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                                    ^

/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'

  ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
                                                                    ^

/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'

  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
                                       ^

/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'

  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
                                          ^

/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'

  if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                   ^

Comment thread task_05/src/test.cpp

ASSERT_EQ(std::format("{:016b}", target_res),
std::format("{:016b}", actual_res))
<< std::format("sorting failed on binary pattern {} {:016b}", i, i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]

        << std::format("sorting failed on binary pattern {} {:016b}", i, i);
                ^

Comment thread task_07/src/tree.cpp
auto [L, R] = root->Split(key);
return {SplayTree(L), SplayTree(R)};
}
void SplayTree::Merge(SplayTree&& other) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: rvalue reference parameter 'other' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

void SplayTree::Merge(SplayTree&& other) {
                                  ^

Comment thread task_07/src/tree.hpp

class SplayTree {
private:
class SplayTreeNode {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: constructor does not initialize these fields: key, value [cppcoreguidelines-pro-type-member-init]

task_07/src/tree.hpp:9:

-     int key;
-     int value;
+     int key{};
+     int value{};

Comment thread task_07/src/tree.hpp
public:
SplayTree() = default;
SplayTree(SplayTree const& other) = delete;
SplayTree(SplayTree&& old);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: move constructors should be marked noexcept [cppcoreguidelines-noexcept-move-operations]

Suggested change
SplayTree(SplayTree&& old);
SplayTree(SplayTree&& old) noexcept ;

Comment thread task_08/src/hashtable.hpp
int size;
int cap;
int scale;
const int step_a = 25;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'step_a' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]

  const int step_a = 25;
            ^

Comment thread task_08/src/hashtable.hpp
int scale;
const int step_a = 25;
int step_b;
const int default_value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'default_value' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]

  const int default_value;
            ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant